package com.david.mydemo.ctl_kafka.consumer;

import com.david.mydemo.ctl_kafka.config.KafkaConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@Slf4j
public class KafkaConsumer {

//    @Autowired
//    RpdOderInfoService rpdOderInfoService;

    @KafkaListener(groupId = KafkaConfig.GROUP_ID, topics = {KafkaConfig.TOPICS})
//    @KafkaListener(groupId = GROUP_ID, topicPartitions = {
//        @TopicPartition(topic = TOPICS, partitions = { PARTION + "" })
//    })
    public void listen(ConsumerRecord<?, ?> record) {
        Optional.ofNullable(record.value()).ifPresent(message -> {
            log.info("【+++++++++++++++++ 消费者record = {}】", record);

//            rpdOderInfoService.save(((Object) message).toString());

//            log.info("【+++++++++++++++++ 消费者message = {}】", message);
        });
    }

}
